package com.mindao.app.basic.controller;

import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mindao.app.common.spring.controller.BaseBaseController;
import com.mindao.app.common.spring.service.util.JsonResult;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：SpringMVC 演示(Freemarker)
/*	 
 * 缺省访问路径：类映射+方法名称映射.do,如/basic/hellofreemarker/ajax.do
 * 缺省返回页面：app/类映射+方法名称映射.ftl, 如app/basic/hellofreemarker/ajax.ftl
 * 
 * @author liguocai
 *
 */
/* 创 建 人：李国才
/* 创建时间：2016年7月8日 下午2:15:18 	
 **/

@Controller
@RequestMapping("/basic/hellofreemarker")
public class HelloFreemarkerController extends BaseBaseController{
	//原生springMVC
	@RequestMapping(method=RequestMethod.GET)
	public String sayHi(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model rhs){
		rhs.addAttribute("account", "admin");
		String rtns= super.rtnDefault(request, response, session, rhs);
		System.out.println(rtns);
		return rtns;
	}
	

	@RequestMapping(method=RequestMethod.GET)
	public String ajax(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model rhs){
		rhs.addAttribute("account", "admin");
		String rtns= super.rtnDefault(request, response, session, rhs);
		System.out.println(rtns);
		return rtns;
	}
	/**
	 * ajax 访问的例子
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @return
	 */
	@ResponseBody
	@RequestMapping//(method=RequestMethod.POST)
	public JsonResult getTaskNumber(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model rhs ){
		//String account=super.getpara("account");
		String account=request.getParameter("account");
		System.out.println("account:"+account);
		Integer taskNumber=Double.valueOf(Math.random()*50).intValue();
		return new JsonResult(JsonResult.SUCCESS,"ok",taskNumber);
	}
}
